package com.threeti.mecool.core.util;

import com.threeti.mecool.core.exception.AssertionFailedException;

/**
 * 断言工具类，用户替代jdk中assert语法
 * <p>
 * 此类中方法应用于判断编码错误，如果为用户输入逻辑判断，请使用ValidationUtils
 */
public abstract class Assert {
	/**
	 * 判断value不为0
	 * @param value int
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void notZero(int value, String errMessage) {
		if (value == 0) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 判断value为0
	 * @param value int
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void isZero(int value, String errMessage) {
		if (value != 0) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 判断value不为0
	 * @param value long
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void notZero(long value, String errMessage) {
		if (value == 0) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 判断value为0
	 * @param value long
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void isZero(long value, String errMessage) {
		if (value != 0) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 判断target为null
	 * @param target Object
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void isNull(Object target, String errMessage) {
		if (null != target) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 判断target不为null
	 * @param target Object
	 * @param errMessage String 错误信息
	 * @throws AssertionFailedException
	 */
	public static void notNull(Object target, String errMessage) {
		if (null == target) {
			throw new AssertionFailedException(errMessage);
		}
	}

	/**
	 * 无条件抛出断言错误，用于强调性能场景时避免使用字符串链接
	 * @throws AssertionFailedException
	 */
	public static void raiseException(String errMessage) {
		throw new AssertionFailedException(errMessage);
	}
	
}
